<div id="admin_detail_modal" class="modal fade">
  <div class="modal-dialog" >
    <div class="modal-content">
    	<div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title">新增后台用户</h4>
      </div>
      <div class="modal-body">
				<div class="row">

					<div class="form-group">
						<form id="admin_detail_form" action='{:U("Admin/Admin/updateAdmin")}' method="post">
				  	<div class="col-sm-12">
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-top:5px">
								<label for="type" class="control-label">类型：</label>
							</div>
							<div class="col-sm-6">
					      <select class="form-control" id="type" name="type">
					      	<option value="0">仓库管理员</option>
									<option value="1">客服</option>	
								</select>
					    </div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-top:5px">
								<label for="name" class="control-label">用户名：</label>
							</div>
							<div class="col-sm-6">
								<input id="name" name="name" class="form-control"></input>
							</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
				    <div class="col-sm-3" style="padding-top:5px">
							<label for="repository_tree" class="control-label">选择仓库：</label>
						</div>
						<div class="col-sm-6">
							<ul id="repository_tree" class="ztree"></ul>
						</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-top:5px">
								<label for="pwd" class="control-label">密码：</label>
							</div>
							<div class="col-sm-6">
								<input type="password" id="pwd" name="pwd" class="form-control"></input>
							</div>
						</div>
						<div class="col-sm-12">
				  		<br>
				  		<div class="col-sm-1"></div>
					    <div class="col-sm-3" style="padding-top:5px">
								<label for="confirm_pwd" class="control-label">确认密码：</label>
							</div>
							<div class="col-sm-6">
								<input type="password" id="confirm_pwd" name="confirm_pwd" class="form-control"></input>
							</div>
						</div>
					</form>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" onclick="submit()">确认</button>
        <button class="btn btn-default" data-dismiss="modal">返回</button>
    	</div>
		</div>
	</div>
</div>
<script>
$(document).ready(function() {
	loadRepositoryTree('repository_tree', false);
});

function submit(){
	if($('#pwd').val() == '' || $('#pwd').val() != $('#confirm_pwd').val()){
		alert('两次密码输入不一致！');
		return;
	}

	var treeObj = $.fn.zTree.getZTreeObj("repository_tree");
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length == 0){
    alert("请选择一个仓库再执行此操作！");
    return;
  }
  var a_repository_id, b_repository_id;
	if(typeof(nodes[0].a_repository_id) == 'undefined'){
		b_repository_id = nodes[0].b_repository_id;
		a_repository_id = '';
	}else{
		a_repository_id = nodes[0].a_repository_id;
		b_repository_id = '';
	}

	$('#admin_detail_form').ajaxSubmit({
		data:{
	      a_repository_id : a_repository_id,
	      b_repository_id : b_repository_id
	  },
    success:function(data){
        $('#admin_detail_modal').modal('hide');
        location.reload();
    }
	});
}
</script>